package com.zyasdk.util;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.util.Log;
import android.util.Patterns;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;

import java.util.regex.Pattern;

/**
 * Created by Administrator on 2017/11/16.
 * 判断google用户
 */

public class GoogleUtil {
    Pattern emailPattern = Patterns.EMAIL_ADDRESS;



    public static boolean isGoogleUser(String google,Context context){
        Log.e("zlog", "isGoogleUser: "+google);
        if (isGoogleAccount(context)&&isGoogleService(context)&&google.equals("12")) {
            return true;
        }else if (!isGoogleAccount(context)&&!isGoogleService(context)&&google.equals("13")){
            return true;
        }else if (google==null||google.isEmpty()||google.equals("null")){
            return true;
        }
        return false;
    }

    public static  boolean isGoogleAccount(Context context){
        Account[] accounts = AccountManager.get(context).getAccountsByType("com.google");
        Log.e("zlog", "isGoogleAccount: "+accounts.length);
        if (accounts.length>0){
          return true;
        }
        return false;
    }

    public static  boolean isGoogleService(Context context){
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        if (status == ConnectionResult.SUCCESS) {
            Log.e("zlog", "GooglePlayServicesUtil service is available.");
            return true;
        } else {
            Log.e("zlog", "GooglePlayServicesUtil service is NOT available.");
            return false;
        }
    }
}
